package com.ruoyi.project.jiaqin.key.service.impl;

import java.util.List;
import java.util.UUID;

import com.ruoyi.project.jiaqin.val.domain.ClassAttrVal;
import com.ruoyi.project.jiaqin.val.mapper.ClassAttrValMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.jiaqin.key.mapper.ClassAttrKeyMapper;
import com.ruoyi.project.jiaqin.key.domain.ClassAttrKey;
import com.ruoyi.project.jiaqin.key.service.IClassAttrKeyService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 分类属性名Service业务层处理
 *
 * @author admin
 * @date 2020-12-21
 */
@Service
public class ClassAttrKeyServiceImpl implements IClassAttrKeyService
{
    @Autowired
    private ClassAttrKeyMapper classAttrKeyMapper;
    @Autowired
    private ClassAttrValMapper classAttrValMapper;
    /**
     * 查询分类属性名
     *
     * @param id 分类属性名ID
     * @return 分类属性名
     */
    @Override
    public ClassAttrKey selectClassAttrKeyById(String id)
    {
        return classAttrKeyMapper.selectClassAttrKeyById(id);
    }

    /**
     * 查询分类属性名列表
     *
     * @param classAttrKey 分类属性名
     * @return 分类属性名
     */
    @Override
    public List<ClassAttrKey> selectClassAttrKeyList(ClassAttrKey classAttrKey) {
        List<ClassAttrKey> list = classAttrKeyMapper.selectClassAttrKeyList(classAttrKey);
        if(list != null && list.size() != 0){
            for (ClassAttrKey c:list) {
                //查询属性值
                c.setVals(classAttrValMapper.selectClassAttrValListByAttrKeyId(c.getId()));
            }
        }
        return list;
    }

    /**
     * 新增分类属性名
     *
     * @param classAttrKey 分类属性名
     * @return 结果
     */
    @Override
    public int insertClassAttrKey(ClassAttrKey classAttrKey)
    {
        classAttrKey.setId(UUID.randomUUID().toString().replace("-",""));
        return classAttrKeyMapper.insertClassAttrKey(classAttrKey);
    }

    /**
     * 修改分类属性名
     *
     * @param classAttrKey 分类属性名
     * @return 结果
     */
    @Override
    public int updateClassAttrKey(ClassAttrKey classAttrKey)
    {
        return classAttrKeyMapper.updateClassAttrKey(classAttrKey);
    }

    /**
     * 删除分类属性名对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteClassAttrKeyByIds(String ids)
    {
        return classAttrKeyMapper.deleteClassAttrKeyByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除分类属性名信息
     *
     * @param id 分类属性名ID
     * @return 结果
     */
    @Override
    public int deleteClassAttrKeyById(String id)
    {
        return classAttrKeyMapper.deleteClassAttrKeyById(id);
    }
}
